<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>佰林の用户信息</title>
    <link rel="stylesheet" href="/common/layui/css/layui.css">
    <link rel="stylesheet" href="/admin/css/style.css">
    <script src="/common/layui/layui.js"></script>
    <script src="/common/jquery-3.3.1.min.js"></script>
    <script src="/common/vue.min.js"></script>
</head>
<body>
<div id="app">


    <div class="main">
        <div id="fixedData">
            <!--顶栏-->
            <header>
                <h1 v-text="webname"></h1>
                <div class="breadcrumb">
                    <i class="layui-icon">&#xe715;</i>
                    <ul>
                        <li v-for="vo in address">
                            <a v-text="vo.name" :href="vo.url"></a> <span>/</span>
                        </li>
                    </ul>
                </div>
            </header>
            <!--左栏-->
            <div class="left">
                <ul class="cl">
                    <!--顶级分类-->
                    <li v-for="vo,index in menu" :class="{hidden:vo.hidden}">
                        <a href="javascript:;" :class="{active:vo.active}" @click="onActive(index)">
                            <i class="layui-icon" v-html="vo.icon"></i>
                            <span v-text="vo.name"></span>
                            <i class="layui-icon arrow" v-show="vo.url.length==0">&#xe61a;</i> <i v-show="vo.active"
                                                                                                  class="layui-icon active">&#xe623;</i>
                        </a>
                        <!--子级分类-->
                        <div v-for="vo2,index2 in vo.list">
                            <a href="javascript:;" :class="{active:vo2.active}" @click="onActive(index,index2)"
                               v-text="vo2.name"></a>
                            <i v-show="vo2.active" class="layui-icon active">&#xe623;</i>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <!--右侧-->
        <div class="right" id="Right">
            <div class="layui-row">
                <div class="layui-col-lg8">
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-sm" @click="getUserList(1,0)">启用</button>
                        <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" @click="getUserList(1,1)">禁用</button>
                    </div>
                </div>
                <div class="layui-col-lg4" style="text-align: right">
                    <div class="layui-input-inline" style="width: 300px">
                        <input type="text" name="k" value="" placeholder="手机/用户名/邮箱/昵称" class="layui-input key">
                    </div>
                    <button type="button" class="layui-btn sou">搜索</button>
                </div>
            </div>

            <table class="layui-table layui-form">
                <thead>
                <tr>
                    <th><a href="?/admin/user/index/order/uid.html">序号</a></th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>性别</th>
                    <th>真实姓名</th>
                    <th>手机</th>
                    <th>邮箱</th>
                    <th>地址</th>
                    <th><a href="?/admin/user/index/order/reg_time.html">注册时间</a></th>
                    <th><a href="?/admin/user/index/order/login_time.html">最后登录时间</a></th>
                    <th><a href="?/admin/user/index/order/state.html">状态</a></th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr class="id36567" v-for="item,index of userList " :key="index">
                    <td>{{index+1}}</td>
                    <th>{{item.username}}</th>
                    <td>{{item.password}}</td>
                    <td>{{item.sex}}</td>
                    <td>{{item.realName||''}}</td>
                    <td>{{item.phone||''}}</td>
                    <td>{{item.email}}</td>
                    <td>{{item.address}}</td>
                    <td>{{item.registerTime}}</td>
                    <td>{{item.loginTime}}</td>
                    <td >
                        {{item.status ? '禁用' : '启用'}}
                    </td>
                    <td>
                        <button v-if="!item.status" class="layui-btn  layui-btn-warm layui-btn layui-btn-xs" @click="changeStatus(1,item)">禁用</button>
                        <button v-else class="layui-btn  layui-btn-xs" @click="changeStatus(0,item)">启用</button>
                        <button class="layui-btn-normal layui-btn layui-btn-xs" @click="JumpRouter(item.id)">修改</button>
                        <button class="layui-btn  layui-btn-xs layui-btn-danger" @click="delUserListInfo(item.id)">删除</button>
                    </td>
                </tr>

                </tbody>
            </table>

            <div class="page">
                <ul class="pagination">
                    <li style="cursor: pointer" v-for="(item,i) of dataCount" @click="setActivePage(i+1)"><span >{{i+1}}</span></li>
<!--                    <div v-for="(item,i) of dataCount" @click="setActivePage(i+1)">{{i+1}}</div>-->
                </ul>
            </div>


        </div>
    </div>
</div>
<script src="/admin/js/config.js"></script>
<!--<script src="/admin/js/script.js"></script>-->
<script>
    let right = new Vue({
        el:'#Right',
        data: {
            userList:[],
            commodityType:[],
            status:0,
            activePage:1,
            dataCount:5 ,// 分页数
        },
        methods:{
            /*设置当前页数*/
            setActivePage(index){
                this.activePage = index;
                this.getUserList(this.activePage,this.status)
            },
            //获取一共有多少条数据
            getDataCount(){
                $.ajax({
                    url:'showUserList/select',
                    type:'post',
                    data:JSON.stringify({
                        status:this.status,
                    }),
                    contentType: "application/json;charset=UTF-8",
                    success: (data)=> {
                        if(data){
                            this.dataCount = Math.ceil(data.length/10) ;
                        }
                    }
                })
            },

            //修改跳转
            JumpRouter(id){
                window.location = '/toUserUpdate?id='+id;
            },

            //变化状态
            changeStatus(value,item){
                item.status = value;
                $.ajax({
                    url:'showUserList/update',
                    type:'post',
                    data:JSON.stringify(
                        item
                    ),
                    contentType: "application/json;charset=UTF-8",
                    success: (data)=> {
                        changValue = value ? 0 : 1;
                        this.getUserList(this.activePage,changValue);
                    }
                })
            },
            //获取用户列表
                getUserList(activePage,status){
                    $.ajax({
                        url:'showUserList/pageSelect',
                        type:'post',
                        data:JSON.stringify({
                            status:status,
                            pageNum:activePage,
                            pageSize:10
                        }),
                        contentType: "application/json;charset=UTF-8",
                        success: (data)=> {
                            this.userList = data.result;
                        }
                    })
            },
            //删除用户列表的用户信息
            delUserListInfo(id){
                $.ajax({
                    url:'showUserList/delete',
                    type:'post',
                    data:JSON.stringify({
                        id:id
                    }),
                    contentType: "application/json;charset=UTF-8",
                    success: (data)=> {
                        this.getUserList(this.activePage,0)
                    }
                })
            },
        },
        mounted(){
            this.getUserList(this.activePage,0),
            this.getDataCount()
        },
    })

</script>

</body>
</html>
